package com.ymatou.shop.ui.activity;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.ImageButton;
import android.widget.TextView;

import com.ymatou.shop.R;
import com.ymatou.shop.util.GlobalUtil;
import com.ymatou.shop.util.Utils;

public class BaseWithLoginActivity extends BaseHeaderActivity implements OnClickListener{

	private final static int login_request_code = 0;

	@Override
	protected void onActivityResult(int requestCode, int resultCode, Intent data) {
		switch (requestCode) {
		case login_request_code:
			if (resultCode == Activity.RESULT_OK) {
				getTitleLeftButton().setVisibility(View.GONE);
				getTitleLeftImageButton().setVisibility(View.VISIBLE);
				getTitleLeftImageButton().setImageResource(R.drawable.ren);
				getTitleLeftImageButton().setOnClickListener(this);
			} else if (resultCode == Activity.RESULT_FIRST_USER) {
				finish();
			}
			
			else {

			}
			break;

		default:
			break;
		}
		super.onActivityResult(requestCode, resultCode, data);
	}

	@Override
	protected void setupViews() {
		super.setupViews();
		if (getAccount().isLogin()) {
			getTitleLeftButton().setVisibility(View.GONE);
			getTitleLeftImageButton().setVisibility(View.VISIBLE);
			getTitleLeftImageButton().setImageResource(R.drawable.ren);
			getTitleLeftImageButton().setOnClickListener(this);
		} else {
			getTitleLeftButton().setVisibility(View.VISIBLE);
			getTitleLeftButton().setOnClickListener(this);
			getTitleLeftImageButton().setVisibility(View.GONE);
		}
		
	}

	@Override
  public void onClick(View v) {

		switch (v.getId()) {
		case R.id.title_left_image_button:
			GlobalUtil.startActivity(this, UserinfoActivity.class);
			break;
		case R.id.title_left_button:
				Utils.startLoginActivityForResult(this, login_request_code);

			break;

		default:
			break;
		}

	
	  
  }
}
